package com.inch.web.controller;

import com.inch.web.entity.User;
import com.inch.web.entity.UserList;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import java.util.Date;

@Controller
@RequestMapping("/hello")
public class HelloController {
    @RequestMapping("/test1")
    public String test1() {
        System.out.println("test1 hello");
        return "jsp/hello1";
    }
    @RequestMapping("/test2")
    public String test2() {
        System.out.println("test2 hello");
        return "jsp/hello2";
    }

    // http://localhost:8080/hello/helloParam?id=1&name=spring&gender=true&birth=2020/11/11 11:23:35
    //recommend use test4 method to put into a entity
    @RequestMapping("/test3")
    public String test3(Integer id, String name, Boolean gender, Date birth) {
        System.out.println("id:" +id + "name:" + name + "gender:" + gender +"birth" + birth);
        return "index";
    }
    @RequestMapping("/user")
    public String test4(User user){
        System.out.println(user.toString());
        return "index";
    }

    @RequestMapping("/userList")
    public String test5(UserList userList){
        for (User user : userList.getUsers()) {
            System.out.println(user);
        }
        return "index";
    }
    @RequestMapping("/test6/{id}/{name}")
    public String test6(@PathVariable int id, @PathVariable("name") String name1) {
        System.out.println("id:" + id + "\tname:" + name1);
        return "index";
    }

}
